﻿using System;
using System.Data;
using System.IO;
using ExcelLoader;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using MDSAdministration;

namespace MDSAdministrationTest
{
    [TestClass]
    public class LoadModelDataTests
    {
        
        [TestMethod]
        public void LoadSameModelSchemaCompareTest()
        {
            var c = new Common();
            c.LoadSampleData(@"..\..\TestData\SameModel.xlsx");

            ServerMDSDetails s = new ServerMDSDetails();
            s.ServerName = ".";
            s.Database = "MDS_MTN";
            s.ModelVersion = "VERSION_1";
            s.Model = "SandBox";

            DataSet dsServer = DataHelper.GetDataModelDetails(s);

            Assert.AreEqual(dsServer.Tables[0].SchemaNameOnlyEquals(c.dsA.Tables[0]), true);
            Assert.AreEqual(dsServer.Tables[1].SchemaNameOnlyEquals(c.dsA.Tables[1]), true);
            Assert.AreEqual(dsServer.Tables[2].SchemaNameOnlyEquals(c.dsA.Tables[2]), true);
            Assert.AreEqual(dsServer.Tables[3].SchemaNameOnlyEquals(c.dsA.Tables[3]), true);

        }

        

        [TestMethod]
        public void LoadSameModelBuildModels()
        {
            
            Common.LoadServer();

            CheckStates cStates = new CheckStates();

            CompareModel modelA = new CompareModel();
            CompareModel modelB = new CompareModel();

            var c = new Common();
            c.LoadSampleData(@"..\..\TestData\SameModel.xlsx");
            BusinessHelper.buildModel(c.dsA, modelA);
            BusinessHelper.buildModel(c.dsB, modelB);

            var compResult = BusinessHelper.CompareModels(modelA, modelB, cStates, Common.ServerA, Common.ServerB);

            List<ComparedObject> lco = new List<ComparedObject>(compResult.Values);

            foreach (var co in lco)
            {
                Assert.AreEqual(co.locationType, ObjectStatus.Same);
            }
        }
    }
}
